﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using UI.ParentForm;
using UI.Lib;
using UI.Lib.Factory;
using System.Collections;
using Com.Seezt.Skins;

namespace UI.CommonForm
{
    public partial class FrmSaveStn : BaseForm
    {
        private string _pageName;

        public string PageName
        {
            get { return _pageName; }
            set { _pageName = value; }
        }

        public FrmSaveStn()
        {
            InitializeComponent();

            this.txtSntName.Focus();
            if (Context.IsSuperUser)
            {
                this.chkpublic.Enabled = true;
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.Size = new Size(450, 220);
        }

        private void btnCanche_Click(object sender, EventArgs e)
        {
            _result = false;
            this.Close();
        }

        private bool _result = false;

        public bool Result { get { return _result; } }

        private void btnOk_Click(object sender, EventArgs e)
        {
            string text = txtSntName.Text;

            if (string.IsNullOrEmpty(text))
            {
                MsgBox.Show(this, "方案名称不能为空！");
                txtSntName.Focus();
                return;
            }

            if (text.IndexOf(":") > -1)
            {
                MsgBox.Show(this, "方案中存在特殊符号“:”， 请移除！");
                txtSntName.Focus();
                return; 
            }

            Hashtable table = new Hashtable();
            table["name"] = txtSntName.Text;
            table["page"] = PageName;

            string rst = CommonHelper.Entity.ExecFunScalar("checkstnname", table);
            table = null;

            if (!String.IsNullOrEmpty(rst))
            {
                MsgBox.Show(this, "方案名称已经存在，请重新录入！");
                txtSntName.Focus();
                return;
            }

            _result = true;
            this.Close();
        }

        public string GetSntName { get { return this.txtSntName.Text; } }

        public bool GetChkValue { get { return this.chkpublic.Checked; } }
    }
}
